home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / net / tf02.lha / TinyFugue / tf-lib / replace.tf < prev    next >
Text File  |  1995-08-12  |  610b  |  23 lines

  1. ;;;; Replace
  2. ;;; syntax:  /replace <old> <new> <string>
  3. ;;; Echoes <string>, with each occurance of <old> replaced by <new>.
  4. ;;; <old> and <new> must be single words.
  5.  
  6. ;;; Example:
  7. ;;; command: /replace foo bar Whee foofle foobar
  8. ;;; output:  Whee barfle barbar
  9.  
  10. /~loaded replace.tf
  11.  
  12. /def -i replace = \
  13.     /let old=%1%;\
  14.     /let new=%2%;\
  15.     /let left=%;\
  16.     /let right=%-2%;\
  17.     /while /let i=$[strstr(right, old)]%; /test i >= 0%; /do \
  18.          /test left := strcat(left, substr(right, 0, i), new)%;\
  19.          /test right := substr(right, i + strlen(old))%;\
  20.     /done%;\
  21.     /echo - %{left}%{right}
  22.  
  23.